package com.lin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lin.mapper.SysUsersMapper;
import com.lin.pojo.PageVo;
import com.lin.pojo.SysUsers;
import com.lin.service.SysUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUsersMapper, SysUsers>implements SysUsersService {
    @Autowired
    SysUsersMapper sysUsersMapper;

    @Override
    public SysUsers login(SysUsers sysUsers) {
        return sysUsersMapper.login(sysUsers);
    }

    @Override
    public SysUsers querySysUsersbyid(int id) {
        return null;
    }

    @Override
    public Map addSysUsers(SysUsers sysUsers) {
        boolean num = this.save(sysUsers);
        //int num = personMapper.insert(person);
        Map map =new HashMap();
        map.put("code","0");
        map.put("msg","添加失败");
        if(num){
            map.put("code","1");
            map.put("msg","添加成功");
        }
        return map;
    }

    @Override
    public Map delSysUsers(int id) {
        boolean num = this.removeById(id);
        Map map =new HashMap();
        map.put("code","0");
        map.put("msg","删除失败");
        if(num){
            map.put("code","1");
            map.put("msg","删除成功");
        }
        return map;
    }

    @Override
    public Map updateSysUsers(SysUsers sysUsers) {
        boolean num = this.updateById(sysUsers);
        Map map =new HashMap();
        map.put("code","0");
        map.put("msg","修改失败");
        if(num){
            map.put("code","1");
            map.put("msg","修改成功");
        }
        return map;
    }

    @Override
    public PageVo<SysUsers> querySysUsersbycond(SysUsers sysUsers, int pageno, int pagesize) {
        Page<SysUsers> page = new Page<SysUsers>(pageno,pagesize);
        //条件查询
        QueryWrapper<SysUsers> queryWrapper =new QueryWrapper<SysUsers>();
        if(StringUtils.isNotBlank(sysUsers.getLoginId())){
            queryWrapper.like("loginid",sysUsers.getLoginId());
        }
       /* if(person.getBirthday()!=null){
            //查询生日 大于当前指定日期的
            queryWrapper.gt("birthday",person.getBirthday());
        }*/
        Page<SysUsers> page1 = this.page(page,queryWrapper);
        PageVo<SysUsers> pageVo = new PageVo<SysUsers>();
        pageVo.setTotal(page1.getTotal());
        pageVo.setRows(page1.getRecords());
        return pageVo;
    }
}
